<div class="list-box-function">
    <div class="page-guide">


        <?php
            //获取当前文件名
            $file= "data_list.php";
            $showPages = 10; // 显示的页码数量,超出则显示省略
            $startPage = max(1, $data['now_page'] - 2); // 当前页向前偏移
            $endPage = min($data['page_sum'], $startPage + $showPages - 1);

            // 如果靠近末尾，则调整起始页
            if ($endPage - $startPage < $showPages - 1) {
                $startPage = max(1, $endPage - $showPages + 1);
            }
        ?>

        <!--首页和前一页保持不变 -->
        <?php if ($data['now_page'] == 1) { ?>
            <span>首页</span>
            <span>前一页</span>
        <?php } else { ?>
            <a href="<?echo $file ?>?<?= $data['url_parameter'] ?>&now_page=1">首页</a>
            <a href="<?echo $file ?>?<?= $data['url_parameter'] ?>&now_page=<?= $data['now_page'] - 1 ?>">前一页</a>
        <?php } ?>

        <!--页码展示逻辑修改 -->
        <?php for ($i = 0; $i < $data['page_sum']; $i++) :
            $pageNumber = $i + 1;

            // 判断是否显示页码
            if (
                $pageNumber == 1 ||
                $pageNumber == $data['page_sum'] ||
                ($pageNumber >= $startPage && $pageNumber <= $endPage)
            ) : ?>
                <?php if ($pageNumber == $data['now_page']) : ?>
                    <span><?= $pageNumber ?></span>
                <?php else : ?>
                    <a href="<?echo $file ?>?<?= $data['url_parameter'] ?>&now_page=<?= $pageNumber ?>"><?= $pageNumber ?></a>
                <?php endif; ?>

                <!-- 添加省略号 -->
            <?php elseif ($i == $startPage - 2) : ?>
                <span>...</span>
            <?php elseif ($i == $endPage) : ?>
                <span>...</span>
            <?php endif; ?>
        <?php endfor; ?>

        <!--后一页和末页保持不变 -->
        <?php if ($data['now_page'] == $data['page_sum']) { ?>
            <span>后一页</span>
            <span>末页</span>
        <?php } else { ?>
            <a href="<?echo $file ?>?<?= $data['url_parameter'] ?>&now_page=<?= $data['now_page'] + 1 ?>">后一页</a>
            <a href="<?echo $file ?>?<?= $data['url_parameter'] ?>&now_page=<?= $data['page_sum'] ?>">末页</a>
        <?php } ?>




        <div class="jump_page_box"  >
            <!--//加入select表，让客户直接选择页码跳转-->

            <label>跳转</label>
            <div class="select_content">
                <select name="page_select" id="page_select" class="layui-select"
                        onchange="window.location.href = '<?echo $file ?>?<?= $data['url_parameter'] ?>&now_page=' + this.value">
                    <?php for ($i = 1; $i <= $data['page_sum']; $i++) : ?>
                        <option value="<?= $i ?>"
                            <?php if ($i == $data['now_page']) echo 'selected'; ?>>
                            <?= $i ?>
                        </option>
                    <?php endfor; ?>
                </select>
            </div>

        </div>




    </div>




</div>


